package threading;

import sun.awt.image.ImageWatched;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Microsoft
 * Date: 2023-07-13
 * Time: 17:15
 */
public class ThreadDemo19 {
    public static void main(String[] args) throws InterruptedException {
        BlockingDeque<String> queue = new LinkedBlockingDeque<>();
        //阻塞队列的核心方法，主要有两个：
        //1.put入队列
        queue.put("hello1");
        queue.put("hello2");
        queue.put("hello3");
        queue.put("hello4");
        queue.put("hello5");


        //2.take出队列
        String result = null;
        result = queue.take();
        System.out.println(result);

        result = queue.take();
        System.out.println(result);

        result = queue.take();
        System.out.println(result);

        result = queue.take();
        System.out.println(result);

        result = queue.take();
        System.out.println(result);

        result = queue.take();//由于此时队列为空，第六次take会陷入阻塞状态
        System.out.println(result);
    }
}
